package com.zkq.lvse.common.utils;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * 
 * @author zkq
 * 
 * 反射工具类
 * 获取泛型类型Class
 *
 */
public class ReflectionUtils {

	@SuppressWarnings("unchecked")
	public static <T> Class<T> getSuperClass(final Class clz) {
		return getSuperClass(clz,0);
	}
	@SuppressWarnings("unchecked")
	private static Class getSuperClass(Class clz, int index) {
		Type genType = clz.getGenericSuperclass();

		if (!(genType instanceof ParameterizedType)) {
			return Object.class;
		}

		Type[] params = ((ParameterizedType) genType).getActualTypeArguments();

		if (index >= params.length || index < 0) {
			return Object.class;
		}
		if (!(params[index] instanceof Class)) {
			return Object.class;
		}

		return (Class) params[index];
	}

	
}
